//发射武器 0烟雾弹 1手雷 2发射器 3荧光弹
params ["_unit","_target", "_type"];
switch (_type) do
{
	case 0:{
		private _smoke = [];
		{ 
			if((_x select 0) in magazines _unit)then
				{_smoke pushback (_x select 1)} 
		} forEach [["SmokeShell","SmokeShellMuzzle"],["SmokeShellBlue","SmokeShellBlueMuzzle"],["SmokeShellYellow","SmokeShellYellowMuzzle"],["SmokeShellGreen","SmokeShellGreenMuzzle"],["SmokeShellPurple","SmokeShellPurpleMuzzle"],["SmokeShellOrange","SmokeShellOrangeMuzzle"],["SmokeShellRed","SmokeShellRedMuzzle"]];
		
		if (count _smoke > 0) then
		{
			if(_unit != _target) then{_unit setDir (_unit getDir _target)};
			_unit forceWeaponFire [_smoke select 0,_smoke select 0];
		};
	};
	case 1:{
		if(_unit != _target) then{_unit setDir (_unit getDir _target)};
		_unit forceWeaponFire ["HandGrenadeMuzzle","HandGrenadeMuzzle"];
		_unit forceWeaponFire ["MiniGrenadeMuzzle","MiniGrenadeMuzzle"];
	};
	case 2:{
		if(_unit != _target && {!isNull _target}) then
			{
				private _weapon = [secondaryWeapon _unit] call fn_getWeaponType;
				if(_weapon != "")then
				{
					_unit setUnitPos "UP";
					_unit fire secondaryWeapon _unit;
					_unit setDir (_unit getDir _target); 
					_unit setVariable ["as_fired_target", _target];

					_unit addEventHandler ["Fired", {
						//修正跟踪目标
						_projectile = _this select 6;
						_target = (_this select 7) getVariable ["as_fired_target", objNull];

						if(!alive _projectile || {isNull _target}) exitWith {};
						[_this select 7,_projectile, _target]spawn{
							params ["_unit", "_projectile", "_target"];
							private _time = time + 15;
							while {alive _projectile && {time < _time}} do {
								_pos0 = getPosASL _projectile;
								_pos1 = getPosASL _target;
								_dir0 = _pos0 vectorFromTo (getPosASL _target);
								_dir1 = (getPosASL _target) vectorFromTo _pos0;
								_projectile setVelocityTransformation [
									_pos0,
									_pos1 , 
									velocity _projectile, 
									velocity _projectile, 
									_dir0, 
									_dir1, 
									[0,0,1], 
									[0,0,1],
									0.005
								];
								
								sleep .02;
							};
							_unit removeAllEventHandlers "Fired";
						};
						//_unit removeEventHandler ["Fired",_unit getVariable ["as_fired_index", _index]];//直接移除所有事件
						
					}]; 

					//_unit setVariable ["as_fired_index", _index];

					_unit playMove "AmovPknlMstpSrasWlnrDnon";//改变动作后马上会发射
					_unit setDir (_unit getDir _target); 
				};
			};
	};
	case 3:{
		private _smoke = [];
		{ 
			if((_x select 0) in magazines _unit)then
				{_smoke pushback (_x select 1)} 
		} forEach [["Chemlight_red","ChemlightRedMuzzle"],["Chemlight_green","ChemlightGreenMuzzle"],["Chemlight_yellow","ChemlightYellowMuzzle"],["Chemlight_blue","ChemlightBlueMuzzle"]];
		
		if (count _smoke > 0) then
		{
			_unit addEventHandler ["Fired",{private ["_al_throwable"]; _al_throwable = _this select 6; _shooter = _this select 0;
			[_al_throwable,_shooter,"Chemlight_red","Chemlight_blue","Chemlight_green","Chemlight_yellow"] execvm "AL_grenades\al_grenade.sqf"}];
			
			if(_unit != _target) then{_unit setDir (_unit getDir _target)};
			_unit forceWeaponFire [_smoke select 0,_smoke select 0];
		};
	};
};
